﻿<?php
include_once("../initial.php");
include_once("../dbdriver/devicenumWHandle.php");
include_once("../dbdriver/devicenumRHandle.php");
class devicenumLogic
{
    public function insert_order($array)
    {
        if(is_array($array)==false)
        {
            return false;
        }
        if(count($array)==0)
        {
            return false;
        }
        $whandle = new devicenumWHandle();
        return $whandle->insert_data($array);
    }
    public function get_devicenum($array='', $orderby='', $limit='')
    {
        $rhandle = new devicenumRHandle();
        if($array == '')
        {
            return $rhandle->get_all_data($orderby,$limit);
        }
        else
        {
            return $rhandle->get_some_data($array, $orderby, $limit);
        }
    }
    public function get_devicenum_data_insert($deviceid,$devicetype, $year, $month, $day)
    {
        if($deviceid == "" || $year=="" || $month=="" || $day=="")
        {
            return "";
        }
        $array = array("mid"=>$deviceid, "date"=>$year."-".$month."-".$day);
        $rhandle = new devicenumRHandle();
        $remaininfo = $rhandle->get_some_data($array);
        if(count($remaininfo)<=0)
        {
            //创建新的数据
            $newdata = array("mid"=>$deviceid, "date"=>$year."-".$month."-".$day);
            if($devicetype=="1")
            {
                //按照节
                $remain=serialize(array(1,1,1,1, 1,1,1,1, 1,1,1,1));
            }
            else
            {
                $remain="1";
            }
            $newdata['remain']=$remain;
            $whandle = new devicenumWHandle();
            $whandle->insert_data($newdata);
        }
        return $rhandle->get_some_data($array);
    }
    public function get_devicenum_data($deviceid, $year, $month, $day)
    {
        if($deviceid == "" || $year=="" || $month=="" || $day=="")
        {
            return "";
        }
        $array = array("mid"=>$deviceid, "date"=>$year."-".$month."-".$day);
        $rhandle = new devicenumRHandle();
        return $rhandle->get_some_data($array);
    }
    public function get_devicenum_num($array='')
    {
        $rhandle = new devicenumRHandle();
        return $rhandle->get_devicenum_num($array);
    }
    public function update_devicenum($array,$id)
    {
        $handle = new devicenumWHandle();
        return $handle->update_devicenum($array,$id);
    }
    public function delete_devicenum($id)
    {
        $handle = new devicenumWHandle();
        return $handle->delete_devicenum($id);
    }
    public function delete_devicenum_by_mid($mid)
    {
        $handle = new devicenumWHandle();
        return $handle->delete_devicenum_by_mid($mid);
    }
}
?>
